// 监听来自popup的消息
// @ts-ignore
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
  console.log('message', message)
  try {
    if (message.type === 'FILL_INPUT') {
      // 查找所有input元素并填充值
      const select = message.value;
      if (select) {
        for (let i = 0; i < select.length; i++) {
          const selector = document.querySelector(select.selector);
          if (selector) {
            selector.value = select.value;

          }
        }
        const submit = document.querySelector(message.submit);
        if (submit) {
          submit.click();
        }
      }
    }
  } catch (error) {
    console.log(error)
  }
});
